package org.jeecg.modules.yusuan.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.jeecg.modules.yusuan.entity.CaiwuYusuan;
import org.jeecg.modules.yusuan.entity.CaiwuZhijie;
import org.jeecg.modules.yusuan.entity.NianDuHuiZong;
import org.jeecg.modules.yusuan.mapper.CaiwuYusuanMapper;
import org.jeecg.modules.yusuan.mapper.CaiwuZhijieMapper;
import org.jeecg.modules.yusuan.service.ICaiwuYusuanService;
import org.jeecg.modules.yusuan.service.ICaiwuZhijieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: caiwu_yusuan
 * @Author: jeecg-boot
 * @Date:   2020-06-15
 * @Version: V1.0
 */
@Service
public class CaiwuZhijieServiceImpl extends ServiceImpl<CaiwuZhijieMapper, CaiwuZhijie> implements ICaiwuZhijieService {

    @Autowired
    private SysDepartMapper sysDepartMapper;

    @Override
    public void saveYuSuanData(List<CaiwuZhijie> zhijieList) {
        if(CollectionUtils.isNotEmpty(zhijieList)){
            this.saveOrUpdateBatch(zhijieList);
        }

        this.baseMapper.deleteNotExist(zhijieList);
    }

    @Override
    public List<NianDuHuiZong> nianduhuizong(String orgCode) {
        List<NianDuHuiZong> retList = new ArrayList<>();
//        List<SysDepart> departList = sysDepartMapper.getSubOrgCodeByPcode(orgCode);
//        if(CollectionUtils.isEmpty(departList))
//            return retList;
//        List<NianDuHuiZong> yuansuanList = this.baseMapper.yusuanhuizong(departList);
//        List<NianDuHuiZong> zhibiaoList = this.baseMapper.zhibiaohuizong(departList);
//        Map<String,NianDuHuiZong> ysMap = new HashMap<>();
//        if(CollectionUtils.isNotEmpty(yuansuanList)){
//            retList.addAll(yuansuanList);
//            yuansuanList.forEach(item ->{
//                ysMap.put(item.getCategoryId(),item);
//            });
//        }
//
//        if(CollectionUtils.isNotEmpty(zhibiaoList)){
//            zhibiaoList.forEach(zhibiao ->{
//                NianDuHuiZong item = ysMap.get(zhibiao.getCategoryId());
//                if(null == item){
//                    retList.add(zhibiao);
//                }else{
//                    item.setHjzhibiao(zhibiao.getHjzhibiao());
//                }
//            });
//        }
        return retList;
    }

    @Override
    public List<CaiwuZhijie> listData(String deptId,String deptCode, String pid) {
        return this.baseMapper.listData(deptId,deptCode,pid);
    }
}
